package com.zjy.business.login.manager.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.zjy.business.login.domain.manager.form.ManagerLoginForm;
import com.zjy.business.login.domain.manager.form.ManagerUserEditInfoForm;
import com.zjy.business.login.domain.manager.vo.ManagerLoginVo;
import com.zjy.business.login.domain.manager.vo.ManagerUserInfoVo;
import com.zjy.business.login.manager.service.ManagerSysAuthService;
import com.zjy.business.system.domain.manager.form.ManagerSysEditPasswordForm;
import com.zjy.business.system.domain.manager.vo.ManagerSysMenuListVo;
import com.zjy.log.annotation.OperationLog;
import com.zjy.log.enums.LogBusinessType;
import com.zjy.web.domain.model.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 后台管理-登录
 */
@RestController
@RequestMapping("/manager/sysAuth")
@Validated
@RequiredArgsConstructor
public class ManagerSysAuthController {

    final private static String MODULE_NAME = "后台用户-登录";
    private final ManagerSysAuthService sysAuthService;

    /**
     * 账号密码登录
     */
    @SaIgnore
    @OperationLog(title = MODULE_NAME, logBusinessType = LogBusinessType.GRANT)
    @PostMapping("/formLogin")
    public Result<ManagerLoginVo> formLogin(@Validated @RequestBody ManagerLoginForm form) {
        return Result.SUCCESS(sysAuthService.formLogin(form));
    }

    /**
     * 获取当前用户信息
     */
    @GetMapping("/getUserInfo")
    public Result<ManagerUserInfoVo> getUserInfo() {
        return Result.SUCCESS(sysAuthService.getUserInfo());
    }

    /**
     * 获取当前用户菜单列表
     */
    @GetMapping(value = "/queryMenuList")
    public Result<List<ManagerSysMenuListVo>> queryMenuList() {
        return Result.SUCCESS(sysAuthService.queryMenuList());
    }

    /**
     * 修改个人信息
     */
    @PostMapping("/editUserInfo")
    @OperationLog(title = MODULE_NAME, logBusinessType = LogBusinessType.UPDATE)
    public Result<Void> editUserInfo(@RequestBody ManagerUserEditInfoForm form) {
        sysAuthService.editUserInfo(form);
        return Result.SUCCESS();
    }

    /**
     * 修改密码接口
     */
    @PostMapping("/editPassword")
    @OperationLog(title = MODULE_NAME, logBusinessType = LogBusinessType.UPDATE)
    public Result<Void> editPassword(@RequestBody ManagerSysEditPasswordForm form) {
        sysAuthService.editPassword(form);
        return Result.SUCCESS();
    }
}
